const Service = require('../../../core/service/ApiService');
const {Transactional} = require('../../../../plugin/egg-sequelize-transactional');

class AgedSvc extends Service {

    //搜索老人列表
    async searchList(pn, ps, kw, town_id) {
        const dao = this.service.admin.aged.dao;
        return {
            list: await dao.searchAged(pn, ps, kw, town_id)
        }
    }

    //批量删除老人信息
    @Transactional()
    async deleteAged(arr) {
        const dao = this.service.admin.aged.dao;
        await dao.deleteAged(arr);
    }

    //编辑老人信息
    async editAged(body) {
        body.birth = body.id_card_num.substr(7, 8);
        await this.service.admin.aged.dao.editAged(body)
    }

    //老人管理查看统计
    async viewStatistic(aged_id) {
        const [begin, end] = this.helper.getMonthBeginEnd(new Date());
        return this.service.admin.dataany.main.analyzeSvcItem(begin, end, null, aged_id);
    }
}

module.exports = AgedSvc;
